package com.cskaoyan.service;

import com.cskaoyan.bean.MarketAddress;
import com.cskaoyan.bean.MarketAddressExample;
import com.cskaoyan.bean.StorageInfo.StorageVo;
import com.cskaoyan.bean.address.AddressInfo;
import com.cskaoyan.mapper.MarketAddressMapper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 
 * 创建日期: 2022/05/07 16:11
 * @author wangyonghong
 */
@Service
public class AddressServiceImpl implements AddressService {
    @Autowired
    MarketAddressMapper marketAddressMapper;
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    static Date birthday =new Date();
    @Override
    public int save(MarketAddress marketAddress) {
        marketAddress.setUserId(1);
        if(marketAddress.getId()==0){
            marketAddress.setAddTime(birthday);

            marketAddressMapper.insert(marketAddress);

        }else {
            marketAddress.setUpdateTime(birthday);
            marketAddressMapper.updateByPrimaryKey(marketAddress);
        }
        return marketAddress.getId();
    }
    @Override
    public void delete(Integer id) {
      marketAddressMapper.deleteByPrimaryKey(id);

    }

    @Override
    public MarketAddress detail(Integer id) {
        MarketAddress marketAddress = marketAddressMapper.selectByPrimaryKey(id);
        return marketAddress;
    }

    @Override
    public AddressInfo list() {
        AddressInfo storageVo = new AddressInfo();
        List<MarketAddress> marketAddresses = marketAddressMapper.selectByExample(new MarketAddressExample());
        marketAddresses.size();
        storageVo.setList(marketAddresses);
        storageVo.setTotal( marketAddresses.size());
        storageVo.setPages(1);
        storageVo.setPage(1);
        storageVo.setLimit( marketAddresses.size());
        return storageVo;
    }


}
